﻿//BUT: does it also make sense? maybe eliminate this peace of code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// Maybe this filter will die soon...
    /// </summary>
    public class MyLuminance : BaseImageFilter
    {
        /// <summary>
        /// No params needed at all...
        /// </summary>
        public MyLuminance()
        {
        }

        /// <summary>
        /// used to create a copy
        /// </summary>
        /// <param name="_myLuminance"></param>
        internal MyLuminance(MyLuminance _myLuminance)
        {

        }

        /// <summary>
        /// Executes this filter
        /// </summary>
        /// <param name="_bitmap"></param>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            UnsafeBitmap bitmap = _bitmap;
            int y = 0;
            int x = 0;

            int nHeight = bitmap.Height;
            int nWidth = bitmap.Width;

            Color color = Color.Transparent;
            int r = 0;
            int g = 0;
            int b = 0;
            int nValue = 0;

            for (y = 0; y < nHeight; y++)
            {
                for (x = 0; x < nWidth; x++)
                {
                    color = bitmap.GetPixel(x, y);
                    nValue = color.G * color.G * color.B;
                    r = (nValue & 0xFF0000) / 0x10000;
                    g = (nValue & 0x00FF00) / 0x00100;
                    b = (nValue & 0x0000FF);
                    bitmap.SetPixel(x, y, Color.FromArgb(r, g, b));
                }
            }
            return _bitmap;
        }

        /// <summary>
        /// Use this to create a deep copy
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new MyLuminance(this);
        }
    }
}
